<?php
/**
 * Created by PhpStorm.
 * User: ownfi
 * Date: 2017-03-20
 * Time: 15:26
 */

namespace App\Services\Impl;


use App\Common\Constant\CacheKey;
use App\Models\Master;
use App\Services\ICacheService;
use Cache;

class CacheServiceImpl implements ICacheService
{

    public function del($key)
    {
        return Cache::forget($key);
    }

    public function set($key, $value, $minutes = null)
    {
        Cache::put($key, $value, $minutes);
        return Cache::has($key);
    }

    public function get($key, $default = null)
    {
        return Cache::get($key, $default);
    }

    public function currentUser($weixinUserid, Master $user = null, $minutes = 1440)
    {
        $cacheKey = CacheKey::currentUserKey($weixinUserid);
        if ($user === null){
            return Cache::get($cacheKey);
        }else{
            Cache::put($cacheKey, $user, $minutes);
            return Cache::has($cacheKey);
        }
    }

}